package ass.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import ass.beans.UserFriendsBean;
import ass.dao.UserFriendsDAO;
import ass.dao.support.UserFriendsDAOImpl;

/**
 * Servlet implementation class ViewFrdList
 */
public class ViewFrdList extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ViewFrdList() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
		String username = (String) session.getAttribute("username");
		System.out.println(username);

		UserFriendsDAO userFriendsDAO = new UserFriendsDAOImpl();
		List<UserFriendsBean> userFriendsList = userFriendsDAO
				.getUserFriendsAccepted(username);

		// for (UserFriendsBean uBean : userFriendsList){
		// System.out.println(uBean.getUsername());
		// System.out.println(uBean.getUsernameFriend());
		// }
		String nextJSP = "/userFrdList.jsp";
		RequestDispatcher dispatcher = getServletContext()
				.getRequestDispatcher(nextJSP);
		request.setAttribute("userFriendsList", userFriendsList);
		dispatcher.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
